package com.nlp.visualization.core.seg.filter;

import com.nlp.visualization.utils.PropertyUtil;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class SegFilter {


    private Logger logger = LoggerFactory.getLogger(SegFilter.class);
    private HashSet<String> keysSet;


    public HashSet<String> getKeysSet() {
        return keysSet;
    }

    public void setKeysSet(HashSet<String> keysSet) {
        this.keysSet = keysSet;
    }

    public SegFilter() {

        keysSet = new HashSet<>();
    }

    /**
     * 判断停用词是否存在
     *
     * @param o
     * @return
     */
    public boolean IsIncludeStopwords(String o) {

        return keysSet.contains(o);


    }



    public static class FilterBuilder {

        private Logger logger = LoggerFactory.getLogger(FilterBuilder.class);

        private SegFilter segFilter = new SegFilter();


        /**
         * 开启停用词过滤
         *
         * @param flag
         * @return
         */
        public FilterBuilder enableStopwords(boolean flag) {
            if (flag) {
                segFilter.getKeysSet().addAll(CustomDicReader.readstopwords());
            }
            return this;
        }

        /**
         * 开启标点符号过滤
         *
         * @param flag
         * @return
         */
        public FilterBuilder enablePunctuation(boolean flag) {
            if (flag) {
                segFilter.getKeysSet().addAll(CustomDicReader.readpunctuation());
            }
            return this;

        }

        /**
         * 开启自定义的过滤
         *
         * @param keyset
         * @return
         */
        public FilterBuilder enableCostume(Set<String> keyset) {

            segFilter.getKeysSet().addAll(keyset);
            return this;
        }



        /**
         * 完成构建
         *
         * @return
         */
        public SegFilter build() {
            return segFilter;
        }

    }


}

